﻿#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<assert.h>
#include <stdlib.h>
#include<stdbool.h>
#include<string.h>
int my_cmp(const void *e1, const void *e2) 
{	
	return *(int*)e1 - *(int*)e2;
}

void Swap(char *buf1,char *buf2,int width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		int tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;

		buf1++;
		buf2++;
	}


}

void print(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++) 
	{
		printf("%d ",arr[i]);
	}	
}

void my_qsort(void *base, size_t n, size_t width,int(*fp)(const void *e1, const void *e2))
{
	int i = 0;
	for (i = 0; i < n - 1; i++) 
	{
		int j = 0;
		for (j = 0; j < n - 1 - i; j++) 
		{
			if (my_cmp((char*)base + j * width,(char *)base + (j + 1) * width) > 0)
			{
				Swap((char*)base + j * width, (char *)base + (j + 1) * width,width);
			}
		}
	}

}

void test() 
{
	int arr[] = {9,8,7,6,5,4,3,2,1,0};
	int n = sizeof(arr) / sizeof(arr[0]);
	my_qsort(arr,n,sizeof(arr[0]),my_cmp);
	print(arr, n);
}
int main() 
{
	test();
	return 0;
}